/**
 * @param {character[][]} board
 * @return {void} Do not return anything, modify board in-place instead.
 */
var solveSudoku = function (board) {
    solveSudokuLevel(board)
};

function solveSudokuLevel(board) {
    for (let i = 0; i < 9; i++) {
        for (let j = 0; j < 9; j++) {
            if (board[i][j] === ".") {
                for (let m = 1; m <= 9; m++) {
                    if (isValid(board, i, j, m + '')) {
                        board[i][j] = m + ''
                        if (solveSudokuLevel(board)) { return true }
                        board[i][j] = '.'
                    }
                }
                return false
            }
        }
    }
    return true
}

function isValid(board, row, column, num) {
    // 行数字收集
    for (let i = 0; i < 9; i++) {
        if (board[row][i] === num) {
            return false
        }
    }
    // 列数字收集
    for (let i = 0; i < 9; i++) {
        if (board[i][column] === num) {
            return false
        }
    }
    // 宫格数据收集
    let columnR = ~~(column / 3)
    let rowB = ~~(row / 3)
    console.log(rowB, columnR)
    for (let i = rowB * 3; i < (rowB + 1) * 3; i++) {
        for (let j = columnR * 3; j < (columnR + 1) * 3; j++) {
            if (board[i][j] === num) {
                return false
            }
        }
    }
    
    return true
}